package models

import upickle.default._
import Tables._

import scala.collection.immutable.SeqMap
import implicits.Implicits._
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import shared.tool.DefaultPickle

/**
 * Created by yz on 17/5/2022
 */
trait ModelRwT {

  implicit def dateTimeReadWriteDefault: DefaultPickle.ReadWriter[DateTime] = {
    val pattern = "yyyy-MM-dd HH:mm:ss"
    DefaultPickle.readwriter[ujson.Str].bimap[DateTime](x => {
      ujson.Str(x.toString(pattern))
    }, y => {
      val formatter = DateTimeFormat.forPattern(pattern)
      formatter.parseDateTime(y.str)
    })
  }

  implicit val biomFileDataRowRw = macroRW[BiomFileDataRow]
  implicit val fileDataRowRw = macroRW[FileDataRow]
  implicit val groupFileDataRowRw = macroRW[GroupFileDataRow]
  implicit val matrixFileDataRowRw = macroRW[MatrixFileDataRow]
  implicit val missionRowRw = macroRW[MissionRow]
  implicit val missionRowRwDefault = DefaultPickle.macroRW[MissionRow]
  implicit val softRowRw = macroRW[SoftRow]
  implicit val userRowRw = macroRW[UserRow]
  implicit val varInfoFileDataRowRw = macroRW[VarInfoFileDataRow]

  implicit val WorkflowMissionRowRw = macroRW[WorkflowMissionRow]
  implicit val WorkflowMissionRowDefaultRw = DefaultPickle.macroRW[WorkflowMissionRow]
  implicit val keggInfoRowRw = macroRW[KeggInfoRow]

}
